<template>
  <div class="main">
    <div class="header">
      <el-scrollbar style="height: 100%" >
        <el-row>
          <el-col @click.native="selectChange(category)" :class="{selected:category.categoryId==selectKey}" v-for="(category,i) in categoryList" :key="i" :span="24">
            {{ category.categoryName }}
          </el-col>
        </el-row>
      </el-scrollbar>
    </div>
    <div class="bottom">
    </div>
  </div>
</template>


<script>
import { categoryList } from '@/api/shop/category'

export default {
  name: 'ItemCategory',
  data() {
    return {
      selectKey:1,
      categoryList:[]
    }
  },
  methods:{
    selectChange(category){
      this.$emit("categoryChange",category.categoryId)
      this.selectKey=category.categoryId;
    }
  },
  created() {
    categoryList({}).then(res=>{
      this.categoryList=res.rows;
      if(this.categoryList.length>0){
        this.selectKey=this.categoryList[0].categoryId;
        this.$emit("categoryChange",this.selectKey)
      }
    })
  }
}
</script>

<style lang="scss" scoped>
.main {
  height: 600px;
  display: flex;
  flex-direction: column;
  font-size: 17px;
  color: black;

  .header {
    height: 100%;

    .el-row {
      margin: 0;
      margin: 0;
    }

    .el-col {
      text-align: center;
      padding: 10px 0;
      font-size: 13px;

      &:hover {
        background-color: #E5F1FB;
        cursor: pointer;
      }
    }
  }
  .selected {
    text-align: center;
    padding: 10px 0;
    font-size: 13px;
    background-color: #E5F1FB;
  }
  .bottom {
    height: 17px;
    margin-top: -17px;
    background-color: white;
    z-index: 1;
  }
}
</style>
